<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查询车位</title>
    <style>
        html,
        body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: Arial, sans-serif;
            background-image: url('停车场图片.png');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
            display: flex;
            justify-content: center;
            align-items: center;
        }

      .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 400px;
        }

      .title {
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }

      .form-group {
            margin-bottom: 15px;
        }

      .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }

      .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

      .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

      .form-group button:hover {
            background-color: #0056b3;
        }

      .message {
            text-align: center;
            margin-top: 15px;
            color: green;
        }

      .back-button {
            width: 100%;
            padding: 10px;
            background-color: #ccc;
            color: #333;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 15px;
            text-align: center;
            display: block;
        }

      .back-button:hover {
            background-color: #b3b3b3;
        }

      .result-table {
            margin-top: 20px;
            border-collapse: collapse;
            width: 100%;
            display: none;
        }

      .result-table th,
      .result-table td {
            border: 1px solid #ccc;
            padding: 8px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app" class="container">
        <h2 class="title" style="text-align: center; margin-bottom: 30px;">查询车位</h2>
        <form id="searchForm">
            <div class="form-group">
                <label for="seatId">车位编号</label>
                <input type="text" v-model="seatId" id="seatId" required>
            </div>
            <div class="form-group">
                <button type="button" @click="searchSeat">查询</button>
            </div>
        </form>
        <button class="back-button" onclick="goBack()">返回</button>
        <div class="message" id="message"></div>
        <table class="result-table" id="resultTable">
            <thead>
                <tr>
                    <th>车位编号</th>
                    <th>所属停车场</th>
                    <th>车位状态</th>
                </tr>
            </thead>
            <tbody>
                <tr v-if="seat">
                    <td v-text="seat.seatId"></td>
                    <td v-text="seat.parkId"></td>
                    <td v-text="seat.seatStatus"></td>
                </tr>
            </tbody>
        </table>
    </div>

    <script src="layui/layui.js" type="text/javascript"></script>
    <script src="js/vue.js" type="text/javascript"></script>
    <script src="js/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        let vm = new Vue({
            el: "#app",
            data: {
                seatId: "",
                seat: {}
            },
            methods: {
                searchSeat() {
                    let url = "http://localhost:8080/seat/selectById";
                    let params = { seatId: this.seatId };
                    $.get(url, params, (res) => {
                        if (res.code == 200) {
                            this.seat = res.data;
                            document.getElementById('resultTable').style.display = 'table';
                        } else {
                            alert(res.msg);
                            document.getElementById('resultTable').style.display = 'none';
                        }
                    }, "JSON");
                }
            }
        });
    </script>
    <script>
        function goBack() {
            window.location.href = 'seat.html';
        }
    </script>
</body>

</html>